# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  include SimpleCaptcha::ControllerHelpers

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery # :secret => '9d903af83b36c391cbd90f2802744ae5'

  # See ActionController::Base for details 
  # Uncomment this to filter the contents of submitted sensitive data parameters
  # from your application log (in this case, all fields with names like "password"). 
  # filter_parameter_logging :password
  include SuperSimpleAuthenticationSystem
  layout 'application'

end


module ActionView::Helpers::ActiveRecordHelper
  def error_messages_for(object_name, options = {})
    options = options.symbolize_keys
    object = instance_variable_get("@#{object_name}")
    if object && !object.errors.empty?
      content_tag("div",
        content_tag(
          options[:header_tag] || "h2",
          "Возникли ошибки при сохранении."
        ) +
          content_tag("small", "Проблеммы возникли для следующих полей:") +
          content_tag("dl", object.errors.full_messages.collect { |msg| content_tag("dt", msg) }),
        "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
      ) + '<script type="text/javascript">new Effect.Highlight("errorExplanation", { startcolor: "#ffdc73", endcolor: "#e3e3e3" });</script>'
    else
      ""
    end
  end
end
  